home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles Flirt Up Your Life! (German)
/
Singles Flirt Up Your Life.iso
/
data1.cab
/
Statemachine
/
phoneChar.lua
< prev
next >
Wrap
Text File
|
2004-01-29
|
10KB
|
370 lines
-- phone character state machine
beginStateMachine()
onEnter(function(msg)
local phone = getStateObjectFromID(msg.sender);
storeStateObject("phone", phone);
if (phone) then
-- phone does exist
local actionPointName = retrieveData("actionPointName");
local actionPoint = getParent().getFreeActionPoint(phone, actionPointName);
--if (getParent().isOneActionPointLocked(phone)) then
if (not actionPoint) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoint(phone, actionPointName);
end
else
-- phone does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
freeHands(getParent());
end )
onExit(function(msg)
-- local phone = retrieveStateObject("phone");
-- getParent().unlockActionPoints(phone);
-- getParent().stopAllActivities(phone);
-- removeStateObject("phone");
unlockAll("phone");
end )
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
state("callFriendsStart")
onEnter(function(msg)
startAnimation("phoneStart");
this.actionComplete();
sendDelayedMsgThis("takeHandle", 800);
end )
onMsg("takeHandle", function(msg)
local phone = retrieveStateObject("phone");
local handle = phone.createGameObject("handle");
getParent().attachRightObjectHolder(handle);
end )
onMsg("end", function(msg)
if testCancel() then
setState("callFriendsStop");
else
setState("callFriends");
end
end )
state("callFriends")
onEnter(function(msg)
startAnimation("phoneLoop");
local phone = retrieveStateObject("phone");
local callFriends = getParent().startActivity("callFriends", phone);
local length, scale = getActivityLength(callFriends);
sendDelayedMsgThis("talk", random(5000, 10000));
sendDelayedMsgThis("complete", length);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
-- getParent().getGameObjectServer().payMoney(1);
end )
onExit(function(msg)
local phone = retrieveStateObject("phone");
getParent().stopAllActivities(phone);
end )
onMsg("talk", function(msg)
print("talk in wso " .. getParent().getCharacterName());
sendMsg("talk", getParent().mimicSO);
sendDelayedMsgThis("talk", random(5000, 10000));
end )
onMsg("complete", function(msg)
setState("callFriendsStop");
end )
onMsg("testCancel", function(msg)
if testCancel() then
sendMsgThis("complete");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("end", function(msg)
if testCancel() then
sendMsgThis("complete");
else
startAnimation("phoneLoop");
end
end )
state("callFriendsStop")
onEnter(function(msg)
startAnimation("phoneStart", false, -1.0);
sendDelayedMsgThis("dropHandle", 1600);
end )
onMsg("dropHandle", function(msg)
freeHands(getParent());
--getParent().detachRightObjectHolder();
end )
onMsg("end", function(msg)
exitAndGoAway();
end )
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
state("callPizzaStart")
onEnter(function(msg)
startAnimation("phoneStart");
this.actionComplete();
sendDelayedMsgThis("takeHandle", 800);
end )
onMsg("takeHandle", function(msg)
local phone = retrieveStateObject("phone");
local handle = phone.createGameObject("handle");
getParent().attachRightObjectHolder(handle);
end )
onMsg("end", function(msg)
if testCancel() then
setState("callPizzaAborted");
else
setState("callPizza");
end
end )
state("callPizza")
onEnter(function(msg)
startAnimation("phoneLoop");
local phone = retrieveStateObject("phone");
local callPizza = getParent().startActivity("callPizza", phone);
local length, scale = getActivityLength(callPizza);
sendDelayedMsgThis("talk", random(5000, 10000));
sendDelayedMsgThis("complete", length);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
-- getParent().getGameObjectServer().payMoney(1);
end )
onExit(function(msg)
local phone = retrieveStateObject("phone");
getParent().stopAllActivities(phone);
end )
onMsg("talk", function(msg)
print("talk in wso " .. getParent().getCharacterName());
sendMsg("talk", getParent().mimicSO);
sendDelayedMsgThis("talk", random(5000, 10000));
end )
onMsg("canceled", function(msg)
setState("callPizzaAborted");
end )
onMsg("complete", function(msg)
setState("callPizzaStop");
end )
onMsg("testCancel", function(msg)
if testCancel() then
sendMsgThis("canceled");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("end", function(msg)
if testCancel() then
sendMsgThis("canceled");
else
startAnimation("phoneLoop");
end
end )
state("callPizzaStop")
onEnter(function(msg)
startAnimation("phoneStart", false, -1.0);
sendDelayedMsgThis("dropHandle", 1600);
end )
onMsg("dropHandle", function(msg)
freeHands(getParent());
--getParent().detachRightObjectHolder();
end )
onMsg("end", function(msg)
if (testCancel()) then
exitStateMachine();
else
local character = this.getParent();
local staircase, actionPoint = getReachableObjectWithBehavior(character, "staircase", {"topStep"}, true)
-- local staircases = getParent().getObjectsWithBehavior("staircase");
-- local staircase = staircases[1];
-- if (not staircase) then
-- print("no staircase");
-- exitStateMachine();
-- return
-- end
-- -- walk to the closest action point
-- local actionPoint = character.getFreeActionPoint(staircase, "topStep");
--local actionPoint = character.getClosestFreeActionPointToClickPoint(staircase, {"topStep"});
if (actionPoint) then
-- get the walk state object
local wso = character.walkSO;
-- create state machine contexts
local wsoContext = StateMachineContext();
-- store the action point
--wsoContext.storeData("actionPointName", actionPoint.getName());
--wsoContext.storeStateObject("staircase", staircase);
if (wso.walkToActionPoint(actionPoint)) then
print("queue staircaseChar.goGetPizza");
wso.queueStateMachine("staircaseChar.goGetPizza", staircase, wsoContext);
exitStateMachine();
else
print("no path found");
character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
sendMsg("emoThink", character.walkSO);
setState("callPizzaAborted");
end
else
print("no action point found");
character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", character.walkSO);
setState("callPizzaAborted");
end
end
end )
state("callPizzaAborted")
onEnter(function(msg)
startAnimation("phoneStart", false, -1.0);
sendDelayedMsgThis("dropHandle", 1600);
end )
onMsg("dropHandle", function(msg)
freeHands(getParent());
--getParent().detachRightObjectHolder();
end )
onMsg("end", function(msg)
exitStateMachine();
end )
-- state("callPizza")
--
-- onEnter(function(msg)
-- startAnimation("phone");
-- this.actionComplete();
-- end )
--
-- onMsg("queue", function(msg)
-- exitStateMachine();
-- end )
--
-- onMsg("end", function(msg)
-- if (testCancel()) then
-- exitStateMachine();
-- else
-- local staircases = getParent().getObjectsWithBehavior("staircase");
-- local staircase = staircases[1];
-- if (not staircase) then
-- print("no staircase");
-- exitStateMachine();
-- return
-- end
--
-- local character = this.getParent();
--
-- -- walk to the closest action point
-- local actionPoint = character.getFreeActionPoint(staircase, "topStep");
-- --local actionPoint = character.getClosestFreeActionPointToClickPoint(staircase, {"topStep"});
-- if (actionPoint) then
-- -- get the walk state object
-- local wso = character.walkSO;
-- -- create state machine contexts
-- local wsoContext = StateMachineContext();
-- -- store the action point
-- --wsoContext.storeData("actionPointName", actionPoint.getName());
-- --wsoContext.storeStateObject("staircase", staircase);
-- if (wso.walkToActionPoint(actionPoint)) then
-- wso.queueStateMachine("staircaseChar.goGetPizza", staircase, wsoContext);
-- else
-- print("no path found");
-- character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
-- sendMsg("emoThink", character.walkSO);
-- end
-- else
-- print("no action point found");
-- character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
-- sendMsg("emoThink", character.walkSO);
-- end
-- end
-- end )
--
-- state("callOffice")
--
-- onEnter(function(msg)
-- startAnimation("phone");
-- this.actionComplete();
-- end )
--
-- onMsg("queue", function(msg)
-- exitStateMachine();
-- end )
--
-- onMsg("end", function(msg)
-- exitStateMachine();
-- end )
endStateMachine()